package com.zhiwei.controller;

import com.zhiwei.pojo.UserRequests;
import com.zhiwei.service.UserRequestsService;
import com.zhiwei.vo.PageResult;
import com.zhiwei.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@CrossOrigin
@RequestMapping("/requests")
public class UserRequestsController {
    @Autowired
    private UserRequestsService userRequestsService;

    @GetMapping("/list")
    public SysResult getRequestList(PageResult pageResult){
        PageResult pageList = userRequestsService.getRequestList(pageResult);
        return SysResult.success(pageList);
    }
    @PostMapping("/add")
    public SysResult addRequest(@RequestBody UserRequests requests) throws ParseException {
        int i = userRequestsService.addRequest(requests);
        if (i == 1){
            return SysResult.success();
        }
        return SysResult.fail();
    }
    @DeleteMapping("/delete/{id}")
    public SysResult deleteRequest(@PathVariable Integer id){
        System.out.println(id);
        int i = userRequestsService.deleteRequest(id);
        if (i == 1){
            return SysResult.success();
        }
        return SysResult.fail();
    }
}
